package com.zhaodui.fxy;


import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.ContentBody;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import org.jeecg.common.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;


import javax.annotation.PostConstruct;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.StandardSocketOptions;
import java.nio.charset.Charset;
import java.util.*;


public class fxyUtil {

private static  String fxyurl = "https://testsign.egongzheng.com/";
private static  String fxyappid = "zhaodui@test";
private static  String fxyappkey = "c869bc1ea0ee45a8af14e4f48ab50144";



//    https://testsign.egongzheng.com/opensignapi/sign/file/uploadFile.json
//    file 是文件流，文件大小不能超过 5M,只支持 jpg,jpeg,png,bmp
//    格式的图片,mp4,avi 的视频
//    userId 是 String(32) 公证云分配给用户的 ID
//    fileName 是 String(128) 文件名称
//    fileLength 是 Integer 文件大小
//    fileMd5 是 String(32) 文件 md5 值
//    fileType 是 String(4) 上传的文件类型 详见文件类型说明
    public static String uploadFile(
                                    String appCode,RedisUtil redisUtil
            ,fxyUser fxyUser) throws BaseBusinessException {
        String url = fxyurl + "opensignapi/sign/file/uploadFile.json";
        String fileLength = Long.toString(fxyUtil.getfilelenth(fxyUser.getFileUrl()));
        String fileMd5 = fxyUtil.getFileMD5(fxyUser.getFileUrl());
        LinkedHashMap<String, String> reqParam = getcomparaString(fxyappid,appCode, redisUtil);
        reqParam.put("userId", fxyUser.getUserId());
        reqParam.put("fileName", fxyUser.getFileName());
        reqParam.put("fileLength",fileLength);;
        reqParam.put("fileMd5", fileMd5);
        reqParam.put("fileType", fxyUser.getFileType());;
        reqParam.put("from", fxyUser.getFrom());
        String sign = createSignString(reqParam, fxyappkey);
        reqParam.put("sign",sign);

        Map<String, Object> files = new HashMap<>();
        File file = new File(fxyUser.getFileUrl());
        files.put("file",file);
        String result = RequestUtil.postFileMultiPart(url,reqParam,files);
        System.out.println("result="+result);
        JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
        String  resultCode =   myJsonroot.get("resultCode").toString();
        if("E00000".equals(resultCode)){
            return  myJsonroot.get("resultData").toString();
        }else{
            throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
        }
        }


//    userId	是	String		公证云分配给用户的唯一ID
//    file	是	String		签章图片文件流，图片大小不能超过2M,只支持png格式的背景透明图片
//    fileMd5	是	String		签章文件md5值
//    uploadUserName	否	String		上传用户名称
//    evidName	否	String		签章名称
//    isDefault	否	String	0	是否设置为当前默认签章： 1是0否（如果此为企业用户上传的第一个签章，如无系统签章则自动设置为默认签章）
//    signatureType	否	String		签章(字) 类型,1签章 0签字，子用户时必填

    public static String addEvid(
            String appCode,RedisUtil redisUtil
            ,fxyUser fxyUser) throws BaseBusinessException {
        String url = fxyurl + "opensignapi/sign/signature/addEvid.json";
//        String fileLength = Long.toString(fxyUtil.getfilelenth(fxyUser.getFileUrl()));
        String fileMd5 = fxyUtil.getFileMD5(fxyUser.getFileUrl());
        LinkedHashMap<String, String> reqParam = getcomparaString(fxyappid,appCode, redisUtil);
        reqParam.put("userId", fxyUser.getUserId());
        reqParam.put("fileMd5", fileMd5);
        reqParam.put("uploadUserName",fxyUser.getUploadUserName());;
        reqParam.put("evidName", fxyUser.getEvidName());
        reqParam.put("isDefault", fxyUser.getIsDefault());;
        reqParam.put("signatureType", fxyUser.getSignatureType());
        String sign = createSignString(reqParam, fxyappkey);
        reqParam.put("sign",sign);

        Map<String, Object> files = new HashMap<>();
        File file = new File(fxyUser.getFileUrl());
        files.put("file",file);
        String result = RequestUtil.postFileMultiPart(url,reqParam,files);
        System.out.println("result="+result);
        JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
        String  resultCode =   myJsonroot.get("resultCode").toString();
        if("E00000".equals(resultCode)){
            return  myJsonroot.get("resultData").toString();
        }else{
            throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
        }
    }
//    该接口用于用户删除签章（字）。当userId为个人用户时，则只能删除自己的签字，当userId为企业用户时，则只能删除企业下的签章(包括子用户上传的企业签章)，当用户为子用户时，则可删除企业的签章，也可删除自己的签字。当签章或签字，为当前用户的唯一签章或签字，则无法删除。系统签章或签字也是不可删除。
//    userId	是	String		公证云分配给用户的唯一ID
//    evidNo	是	String		签章编号

    public static String delEvid(
            String appCode,RedisUtil redisUtil
            ,fxyUser fxyUser) throws BaseBusinessException {
        String url = fxyurl + "opensignapi/sign/signature/delEvid.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);

        paramMap.put("userId",fxyUser.getUserId());
        paramMap.put("evidNo",fxyUser.getEvidNo());
        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);

        System.out.println("result="+result);
        JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
        String  resultCode =   myJsonroot.get("resultCode").toString();
        if("E00000".equals(resultCode)){
            return  myJsonroot.get("resultData").toString();
        }else{
            throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
        }
    }
//    userId	是	String		公证云分配给用户的唯一ID
//    signatureType	否	String		签章(字)类型，0签字，1签章。子用户时必填
//    该接口用于企业用户查询现有签章（字）。	.当userId为个人时，默认只能查询签字，userId为企业用户时，默认只能查询签章。当userId为子用户时，则可查询企业的签章，或者可查询自己的签字。
    public static String serachEvid(
            String appCode,RedisUtil redisUtil
            ,fxyUser fxyUser) throws BaseBusinessException {
        String url = fxyurl + "opensignapi/sign/signature/serachEvid.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);

        paramMap.put("userId",fxyUser.getUserId());
        paramMap.put("signatureType",fxyUser.getSignatureType());
        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);

        System.out.println("result="+result);
        JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
        String  resultCode =   myJsonroot.get("resultCode").toString();
        if("E00000".equals(resultCode)){
            return  myJsonroot.get("resultData").toString();
        }else{
            throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
        }
    }
//    该接口用于设置默认签章（字）。当userId为个人用户时，则只能设置签字为默认签字。当userId为企业用户，则只能设置签章为默认签章。当userId为子用户时，则可设置企业用户的签章为默认，也可设置自已的签字为默认。
//userId	是	String(32)		用户id
//    evidNo	是	String(32)		签章（字）编号

    public static String setEvidDefault(
            String appCode,RedisUtil redisUtil
            ,fxyUser fxyUser) throws BaseBusinessException {
        String url = fxyurl + "opensignapi/sign/signature/setEvidDefault.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);

        paramMap.put("userId",fxyUser.getUserId());
        paramMap.put("evidNo",fxyUser.getEvidNo());
        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);

        System.out.println("result="+result);
        JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
        String  resultCode =   myJsonroot.get("resultCode").toString();
        if("E00000".equals(resultCode)){
            return  myJsonroot.get("resultData").toString();
        }else{
            throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
        }
    }

//    该接口用于获取用户的默认签章（字），当userId是子用户时则signatureType必填，如signatureType=0时，获取自己的签字，如signatureType=1时，则获取企业用户的签章。
//    当userId是个人时，获取自己的签字，当userId是企业用户时，则获取是企业的签章。
//    返回数据如失败则返回json格式的数据，如成功则返回图片文件流

    public static String getDefaultEvidImg(
            String appCode,RedisUtil redisUtil
            ,fxyUser fxyUser) throws BaseBusinessException {
        String url = fxyurl + "opensignapi/sign/signature/getDefaultEvidImg.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);

        paramMap.put("userId",fxyUser.getUserId());
        paramMap.put("signatureType",fxyUser.getSignatureType());
        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);

        System.out.println("result="+result);
        JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
        String  resultCode =   myJsonroot.get("resultCode").toString();
        if("E00000".equals(resultCode)){
            return  myJsonroot.get("resultData").toString();
        }else{
            throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
        }
    }
//	该接口可以用于获取企业对公账号的银行列表。主要用于企业实名申请。
public static String getCorporateBankList(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {
    String url = fxyurl+"opensignapi/sign/base/getCorporateBankList.json";
    LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);

//    paramMap.put("enterpriseName",fxyUser.getEnterpriseName());
//    paramMap.put("businessLicenseId",fxyUser.getBusinessLicenseId());
//    paramMap.put("orgId",fxyUser.getOrgId());
//    paramMap.put("address",fxyUser.getAddress());
//    paramMap.put("legalPersonType",fxyUser.getLegalPersonType());
//    paramMap.put("legalPersonCard",fxyUser.getLegalPersonCard());
//    paramMap.put("legalPersonPhone",fxyUser.getLegalPersonPhone());
//    paramMap.put("email",fxyUser.getEmail());
//    paramMap.put("contactsName",fxyUser.getContactsName());
//    paramMap.put("contactsPhone",fxyUser.getContactsPhone());
//    paramMap.put("legalPersonName",fxyUser.getLegalPersonName());
//    paramMap.put("legalPersonMobile",fxyUser.getLegalPersonMobile());

    String sign = createSign(paramMap,fxyappkey);
    paramMap.put("sign",sign);
    String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
    System.out.println("result="+result);
    System.out.println("result="+result);
    JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
    String  resultCode =   myJsonroot.get("resultCode").toString();
    if("E00000".equals(resultCode)){
        return  myJsonroot.get("resultData").toString();
    }else{
        throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());

    }

}



//    caseNumber	是	String(32)		案件编号
//    writNumber	是	String(32)		批次编号
//    userId	是	String(32)		进行签署操作的用户ID

    //    doAppletParams
//	该接口用于获取原生APP跳转小程序参数，签署用户进入小程序后完成签署流程。仅用于法人账号、企业子账号或个人用户。
    public static String doAppletParams(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {
        String url = fxyurl+"opensignapi/sign/agreement/doAppletParams.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);

        paramMap.put("caseNumber",fxyUser.getCaseNumber());
        paramMap.put("writNumber",fxyUser.getWritNumber());
        paramMap.put("userId",fxyUser.getUserId());


        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);

        System.out.println("result="+result);
        JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
        String  resultCode =   myJsonroot.get("resultCode").toString();
        if("E00000".equals(resultCode)){
            return  myJsonroot.get("resultData").toString();
        }else{
            throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
        }

    }


//    caseNumber	是	String(32)		案件编号
//    writNumber	是	String(32)		批次编号
//    userId	是	String(32)		进行签署操作的用户ID

//    doAppletParams
//		该接口用于获取微信小程序签署二维码，签署用户扫码进入小程序后完成签署流程。仅用于法人账号、企业子账号或个人用户。
public static String doAppletQr(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {
    String url = fxyurl+"opensignapi/sign/agreement/doAppletQr.json";
    LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);

    paramMap.put("caseNumber",fxyUser.getCaseNumber());
    paramMap.put("writNumber",fxyUser.getWritNumber());
    paramMap.put("userId",fxyUser.getUserId());


    String sign = createSign(paramMap,fxyappkey);
    paramMap.put("sign",sign);
    String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
    System.out.println("result="+result);

    System.out.println("result="+result);
    JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
    String  resultCode =   myJsonroot.get("resultCode").toString();
    if("E00000".equals(resultCode)){
        return  myJsonroot.get("resultData").toString();
    }else{
        throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
    }

}
    public static String registerperson(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {

        String url = fxyurl+"opensignapi/sign/register.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);
        paramMap.put("mobile",fxyUser.getMobile());
        paramMap.put("name",fxyUser.getName());
        paramMap.put("idType",fxyUser.getIdType());
        paramMap.put("idCode",fxyUser.getIdCode());
        paramMap.put("orgId",fxyUser.getOrgId());
        paramMap.put("email",fxyUser.getEmail());
        paramMap.put("address",fxyUser.getAddress());
        paramMap.put("thirdAccount",fxyUser.getThirdAccount());

        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);

        fxjReguserres fxyRes = JSONHelper.fromJsonToObject(result, fxjReguserres.class);
        if("E00000".equals(fxyRes.getResultCode())){
            return fxyRes.getResultData().getUserId();
        }else{
            throw new  BaseBusinessException(fxyRes.getResultCode(),fxyRes.toString());
         }

    }
    //    enterpriseName    //是 String(32) 企业名称
//    businessLicenseId    //是 String(32)    企业组织机构代码或统一社会信用代码（企业唯一标 识）
//    orgId //否 String32() 公证处标识，默认 1，代表鹭江公证处
//    address //否 String(128) 地址
//    legalPersonType    //否 String(4) 法定代表人证件类型 111-身份证
//    legalPersonCard //否 String(32) 法定代表人证件号码
//    legalPersonPhone    //否 String(32) 法定代表人电话
//    email //否 String(128) 邮箱
//    contactsName //是 String(32) 企业联系人姓名
//    contactsPhone //是 String(32) 企业联系人电话
//    legalPersonName //是 String(32) 法定代表人姓名
//    legalPersonMobile    //是 String(20) 法定代表人手机号
    public static String registMainEnterprise(String appCode,RedisUtil redisUtil,fxyUser fxyUser)throws BaseBusinessException {
        String url = fxyurl+"opensignapi/sign/register.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);

        paramMap.put("enterpriseName",fxyUser.getEnterpriseName());
        paramMap.put("businessLicenseId",fxyUser.getBusinessLicenseId());
        paramMap.put("orgId",fxyUser.getOrgId());
        paramMap.put("address",fxyUser.getAddress());
        paramMap.put("legalPersonType",fxyUser.getLegalPersonType());
        paramMap.put("legalPersonCard",fxyUser.getLegalPersonCard());
        paramMap.put("legalPersonPhone",fxyUser.getLegalPersonPhone());
        paramMap.put("email",fxyUser.getEmail());
        paramMap.put("contactsName",fxyUser.getContactsName());
        paramMap.put("contactsPhone",fxyUser.getContactsPhone());
        paramMap.put("legalPersonName",fxyUser.getLegalPersonName());
        paramMap.put("legalPersonMobile",fxyUser.getLegalPersonMobile());

        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);

        fxjReguserres fxyRes = JSONHelper.fromJsonToObject(result, fxjReguserres.class);
        if("E00000".equals(fxyRes.getResultCode())){
            return fxyRes.getResultData().getUserId();
        }else{
            throw new  BaseBusinessException(fxyRes.getResultCode(),fxyRes.toString());
        }
    }


//    userId 是 String(32) 用户 id（企业用户 id）
//    identityType 是 String(4) 身份类型， 100 法定代表人， 9999 其他
//    mobile 是 String(20) 注册手机号
//    name 否 String(100) 用户姓名
//    idType 否 String(8)
//    用户证件类型：
//            111-身份证
//    idCode 否 String(18) 个人用户证件号码（个人唯一标识）
//    authorizationFil
//            eId
//    否 String
//    子 用 户 授 权 书 文 件 id, 来 自 文 件 上 传 接 口 返 回
//    值 ,fileType:1011 子用户授权书， frorm:30 注册。当注
//    册的子用户是法定代表人，可不传，如其他则必填

    public static String registerSubUser(String appCode,RedisUtil redisUtil,fxyUser fxyUser)throws BaseBusinessException {

        String url = fxyurl+"opensignapi/sign/registerSubUser.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);
        paramMap.put("userId",fxyUser.getUserId());
        paramMap.put("identityType",fxyUser.getIdentityType());

        paramMap.put("mobile",fxyUser.getMobile());
        paramMap.put("name",fxyUser.getName());
        paramMap.put("idType",fxyUser.getIdType());
        paramMap.put("idCode",fxyUser.getIdCode());
        paramMap.put("authorizationFileId",fxyUser.getAuthorizationFileId());


        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);

        fxjReguserres fxyRes = JSONHelper.fromJsonToObject(result, fxjReguserres.class);
        if("E00000".equals(fxyRes.getResultCode())){
            return fxyRes.getResultData().getUserId();
        }else{
            throw new  BaseBusinessException(fxyRes.getResultCode(),fxyRes.toString());
        }

    }
//    enterpriseName 是 String(32) 企业名称
//    businessLicenseId    是 String(32)    企业组织机构代码或统一社会信用代码（企业唯一标    识）
//    orgId 否 String32() 公证处标识，默认 1，代表鹭江公证处
//    address 否 String(128) 地址
//    legalPersonType    否 String(4) 法定代表人证件类型 111-身份证
//    legalPersonCard 否 String(32) 法定代表人证件号码
//    legalPersonPhone    否 String(32) 法定代表人电话
//    email 否 String(128) 邮箱
//    contactsName 是 String(32) 企业联系人姓名
//    contactsPhone 是 String(32) 企业联系人电话
//    legalPersonName    是 String(32) 法定代表人姓名
//    legalPersonMobile    是 String(20) 法定代表人手机号
    public static String registerEnterpriseUser(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {

        String url = fxyurl+"opensignapi/sign/registerEnterpriseUser.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);
        paramMap.put("enterpriseName",fxyUser.getEnterpriseName());
        paramMap.put("businessLicenseId",fxyUser.getBusinessLicenseId());
        paramMap.put("orgId",fxyUser.getOrgId());
        paramMap.put("address",fxyUser.getAddress());
        paramMap.put("legalPersonType",fxyUser.getLegalPersonType());
        paramMap.put("legalPersonCard",fxyUser.getLegalPersonCard());
        paramMap.put("legalPersonPhone",fxyUser.getLegalPersonPhone());
        paramMap.put("email",fxyUser.getEmail());
        paramMap.put("contactsName",fxyUser.getContactsName());
        paramMap.put("contactsPhone",fxyUser.getContactsPhone());
        paramMap.put("legalPersonName",fxyUser.getLegalPersonName());
        paramMap.put("legalPersonMobile",fxyUser.getLegalPersonMobile());


        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);

        fxjReguserres fxyRes = JSONHelper.fromJsonToObject(result, fxjReguserres.class);
        if("E00000".equals(fxyRes.getResultCode())){
            return fxyRes.getResultData().getUserId();
        }else{
            throw new  BaseBusinessException(fxyRes.getResultCode(),fxyRes.toString());
        }

    }

//    userId	是	String(32)		公证云企业用户ID
//    inAcctName	是	String(100)		填企业名称或对公账户名
//    businessLicenseId	是	String(32)		营业执照注册号或企业组织机构代码或统一社会信用代码（企业唯一标识）
//    businessLicenseName	否	String(100)		营业执照全称(默认为企业名称)
//    inAcctNo	是	String(32)		企业对公账号
//    inAcctBankName	否	String(32)		对公账户开户行,详见获取对公账号的银行列表接口返回值(银行名称)
//    inAcctBankNo	是	String(32)		企业公账号联行号,详见获取对公账号的银行列表接口返回值(银行联行号)
//    businessLicenseFileId	是	String		营业执照图片,由上传文件接口获得，form：1000实名认证，fileType:1004企业营业执照


    public static String doEnterpriseRealnameRequest(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {

        String url = fxyurl+"opensignapi/sign/realname/doEnterpriseRealnameRequest.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);
        paramMap.put("userId",fxyUser.getUserId());
        paramMap.put("inAcctName",fxyUser.getInAcctName());
        paramMap.put("businessLicenseId",fxyUser.getBusinessLicenseId());
        paramMap.put("businessLicenseName",fxyUser.getBusinessLicenseName());
        paramMap.put("inAcctNo",fxyUser.getInAcctNo());
        paramMap.put("inAcctBankName",fxyUser.getInAcctBankName());
        paramMap.put("inAcctBankNo",fxyUser.getInAcctBankNo());
        paramMap.put("businessLicenseFileId",fxyUser.getBusinessLicenseFileId());


        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);

        System.out.println("result="+result);
        JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
        String  resultCode =   myJsonroot.get("resultCode").toString();
        if("E00000".equals(resultCode)){
            return  myJsonroot.get("resultData").toString();
        }else{
            throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
        }

    }
//    该接口用于对企业实名相关信息进行核验。配合企业实名认证请求接口使用
//userId	是	String(32)		企业用户id
//    mobCode	是	String(6)		对公账号收到的随机验证码
//    orderAmount	是	String(6)		对公账号收到的随机金额(单位(元))如:0.01

    public static String doEnterpriseRealnameVerification(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {

        String url = fxyurl+"opensignapi/sign/realname/doEnterpriseRealnameVerification.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);
        paramMap.put("userId",fxyUser.getUserId());
        paramMap.put("mobCode",fxyUser.getMobCode());
        paramMap.put("orderAmount",fxyUser.getOrderAmount());


        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);

        System.out.println("result="+result);
        JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
        String  resultCode =   myJsonroot.get("resultCode").toString();
        if("E00000".equals(resultCode)){
            return  myJsonroot.get("resultData").toString();
        }else{
            throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
        }

    }


//    userId 是 String(32) 用户 id
//    contacts 是 String(32) 联系人
//    mobile 是 String(20) 手机号
//    provinceName    是 String(64) 省名称,如福建省
//    cityName 是 String(64) 市名称,如厦门市
//    districtName    是 String(64) 区名称,如思明区
//    address 是 String(512) 详细地址
//    email 是 String(256) 邮箱
//    thirdAccount    否 String(32) 第三方账号

    public static String postDeliveryAddress(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {

        String url = fxyurl+"opensignapi/sign/postDeliveryAddress.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode,redisUtil);
        paramMap.put("userId",fxyUser.getUserId());
        paramMap.put("contacts",fxyUser.getContacts());
        paramMap.put("mobile",fxyUser.getMobile());
        paramMap.put("provinceCode",fxyUser.getProvinceCode());
        paramMap.put("provinceName",fxyUser.getProvinceName());
        paramMap.put("cityCode",fxyUser.getCityCode());
        paramMap.put("cityName",fxyUser.getCityName());
        paramMap.put("districtCode",fxyUser.getDistrictCode());
        paramMap.put("districtName",fxyUser.getDistrictName());
        paramMap.put("address",fxyUser.getAddress());
        paramMap.put("email",fxyUser.getEmail());
        paramMap.put("thirdAccount",fxyUser.getThirdAccount());


        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);

        System.out.println("result="+result);
        JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
        String  resultCode =   myJsonroot.get("resultCode").toString();
        if("E00000".equals(resultCode)){
            return  myJsonroot.get("resultData").toString();
        }else{
            throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
        }

    }


    //    个人或子用户 OCR+二要素核验接口
    public static String doRealnameByOCR2Element(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {

        String url = fxyurl+"opensignapi/sign/realname/doRealnameByOCR2Element.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);
        paramMap.put("userId",fxyUser.getUserId());
        paramMap.put("name",fxyUser.getName());
        paramMap.put("idCode",fxyUser.getIdCode());
        paramMap.put("nationalEmblemFileId",fxyUser.getNationalEmblemFileId());
        paramMap.put("humanFaceFileId",fxyUser.getHumanFaceFileId());

        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);
        JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
        String  resultCode =   myJsonroot.get("resultCode").toString();
        if("E00000".equals(resultCode)){
            return  myJsonroot.get("resultData").toString();
        }else{
            throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
        }

    }
    //    个人或子用户银行四要素核验申请接口
    public static String doRealnameVerifyBy4Element(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {

        String url = fxyurl+"opensignapi/sign/realname/doRealnameVerifyBy4Element.json";

        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);


        paramMap.put("userId",fxyUser.getUserId());
        paramMap.put("name",fxyUser.getName());
//        paramMap.put("idType",fxyUser.getIdType());
        paramMap.put("idCode",fxyUser.getIdCode());
        paramMap.put("mobilePhone",fxyUser.getMobile());
        paramMap.put("acctId",fxyUser.getAcctId());
//        paramMap.put("address",fxyUser.getAddress());
//        paramMap.put("thirdAccount",fxyUser.getThirdAccount());

        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);

        JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
        String  resultCode =   myJsonroot.get("resultCode").toString();

        if("E00000".equals(resultCode)){
            return  myJsonroot.get("resultData").toString();
        }else{
            throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
        }

    }

    //    个人或子用户银行四要素核验接口
    public static String doRealnameVerifyByCode(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {

        String url = fxyurl+"opensignapi/sign/realname/doRealnameVerifyByCode.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);
        paramMap.put("userId",fxyUser.getUserId());
        paramMap.put("mobCode",fxyUser.getMobCode());
        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);
        JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
        String  resultCode =   myJsonroot.get("resultCode").toString();
        if("E00000".equals(resultCode)){
            return  myJsonroot.get("resultData").toString();
        }else{
            throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
        }

    }
//    8.7.1. 简述
//    该接口用于用户需要做活体检测时调用此接口。配合个人或子用户唇语视频核验接口使
//            用
    public static String getlpCodebyUserid(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {

        String url = fxyurl+"opensignapi/sign/realname/doRealnameByLipCode.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);
        paramMap.put("userId",fxyUser.getUserId());
        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);
        JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
        String  resultCode =   myJsonroot.get("resultCode").toString();
        if("E00000".equals(resultCode)){
            return  myJsonroot.get("resultData").toString();
        }else{
            throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
        }

    }
    //    8.7.1. 简述
//    该接口用于用户需要做活体检测时调用此接口。配合个人或子用户唇语视频核验接口使
//            用
    public static String doRealnameVerifyByLipCode(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {

        String url = fxyurl+"opensignapi/sign/realname/doRealnameVerifyByLipCode.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);
        paramMap.put("userId",fxyUser.getUserId());
        paramMap.put("lipCode",fxyUser.getLipCode());
        paramMap.put("fileIds",fxyUser.getFileIds());
        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);

        JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
        String  resultCode =   myJsonroot.get("resultCode").toString();


        if("E00000".equals(resultCode)){
            return  myJsonroot.get("resultData").toString();
        }else{
            throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
        }

    }

//    个人或子用户重发银行四要素验证码接口
    public static String doRealnameVerifyByResendCode(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {

        String url = fxyurl+"opensignapi/sign/realname/doRealnameVerifyByResendCode.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);
        paramMap.put("userId",fxyUser.getUserId());
        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);

        JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
        String  resultCode =   myJsonroot.get("resultCode").toString();


        if("E00000".equals(resultCode)){
            return  myJsonroot.get("resultData").toString();
        }else{
            throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
        }

    }
    //    用户生成 CA 接口
    public static String doRealnameByCA(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {

        String url = fxyurl+"opensignapi/sign/realname/doRealnameByCA.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);
        paramMap.put("userId",fxyUser.getUserId());
        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);

        JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
        String  resultCode =   myJsonroot.get("resultCode").toString();


        if("E00000".equals(resultCode)){
            return  myJsonroot.get("resultData").toString();
        }else{
            throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
        }

    }




//    https://testsign.egongzheng.com/opensignapi/sign/agreement/addAgreementWithBusiness.json

    //   该接口用于生成文书，支持同时生成多份文书
    public static String addAgreementWithBusiness(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {

        String url = fxyurl+"opensignapi/sign/agreement/addAgreementWithBusiness.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);
        paramMap.put("userId",fxyUser.getUserId());
        paramMap.put("orgId",fxyUser.getOrgId());
        paramMap.put("businessType",fxyUser.getBusinessType());
        JSONArray jjsonarray = getAgreementInfos(fxyUser.getAgreementCode(),fxyUser.getTemplateCode(),fxyUser.getAgreementName(),fxyUser.getConmapList(),fxyUser.getUserIds(),fxyUser.getSignatorys());
        paramMap.put("agreementInfos",jjsonarray.toString());

        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);

        JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
        String  resultCode =   myJsonroot.get("resultCode").toString();

        if("E00000".equals(resultCode)){
            return  myJsonroot.get("resultData").toString();
        }else{
            throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
        }

    }
    //   该接口用于生成文书，支持同时生成多份文书
//    caseNumber	否	String(32)		案件编号，将本次生成的文书关联（补充）到旧的案件下,通过生成文书接口获取
//    userId	是	String(32)		发起人用户ID
//    orgId	否	String(32)	1	公证处ID，默认1（代表鹭江公证处）
//    extra	否	String(512)		非必填，额外信息，签署后回调时原样返回
//    businessType	是	String(4)		业务类型 详见 业务类型表
//    processNumber	是	String(32)		流程号，需要向公证签系统线下获取
//    sendAgreement	否	String(1)		是否发送文书，0未发送文书， 1发送文书。默认为0未发送文书

    public static String addAgreementByProcessNumber(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {

        String url = fxyurl+"opensignapi/sign/agreement/addAgreementByProcessNumber.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);

        paramMap.put("caseNumber",fxyUser.getCaseNumber());
        paramMap.put("userId",fxyUser.getUserId());
        paramMap.put("orgId",fxyUser.getOrgId());
        paramMap.put("businessType",fxyUser.getBusinessType());
        paramMap.put("processNumber",fxyUser.getProcessNumber());
        paramMap.put("sendAgreement",fxyUser.getSendAgreement());

        JSONArray jjsonarray = getAgreementInfos(fxyUser.getAgreementCode(),fxyUser.getTemplateCode(),fxyUser.getAgreementName(),fxyUser.getConmapList(),fxyUser.getUserIds(),fxyUser.getSignatorys());
        paramMap.put("agreementInfos",jjsonarray.toString());

        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);

        JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
        String  resultCode =   myJsonroot.get("resultCode").toString();

        if("E00000".equals(resultCode)){
            return  myJsonroot.get("resultData").toString();
        }else{
            throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
        }

    }

    public static agreementres addAgreementByProcessNumberreturnobject(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {

        String url = fxyurl+"opensignapi/sign/agreement/addAgreementByProcessNumber.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);

        paramMap.put("caseNumber",fxyUser.getCaseNumber());
        paramMap.put("userId",fxyUser.getUserId());
        paramMap.put("orgId",fxyUser.getOrgId());
        paramMap.put("businessType",fxyUser.getBusinessType());
        paramMap.put("processNumber",fxyUser.getProcessNumber());
        paramMap.put("sendAgreement",fxyUser.getSendAgreement());

        JSONArray jjsonarray = getAgreementInfos(fxyUser.getAgreementCode(),fxyUser.getTemplateCode(),fxyUser.getAgreementName(),fxyUser.getConmapList(),fxyUser.getUserIds(),fxyUser.getSignatorys());
        paramMap.put("agreementInfos",jjsonarray.toString());

        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);

        agreementres agreementrestmp =JSONHelper.fromJsonToObject(result, com.zhaodui.fxy.agreementres.class);
        String  resultCode =   agreementrestmp.getResultCode();

        if("E00000".equals(resultCode)){
            return  agreementrestmp;
        }else{
            throw new  BaseBusinessException( resultCode,agreementrestmp.getResultDesc());
        }

    }



    public static agreementres addAgreementByProcessNumberreturnobjectbatch(String appCode,RedisUtil redisUtil,fxyUser fxyUser,List<fxyUser> listcon) throws BaseBusinessException {

        String url = fxyurl+"opensignapi/sign/agreement/addAgreementByProcessNumber.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);

        paramMap.put("caseNumber",fxyUser.getCaseNumber());
        paramMap.put("userId",fxyUser.getUserId());
        paramMap.put("orgId",fxyUser.getOrgId());
        paramMap.put("businessType",fxyUser.getBusinessType());
        paramMap.put("processNumber",fxyUser.getProcessNumber());
        paramMap.put("sendAgreement",fxyUser.getSendAgreement());
        JSONArray jjsonarray = getAgreementInfosfromlist(listcon);
        paramMap.put("agreementInfos",jjsonarray.toString());
        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);

        agreementres agreementrestmp =JSONHelper.fromJsonToObject(result, com.zhaodui.fxy.agreementres.class);
        String  resultCode =   agreementrestmp.getResultCode();

        if("E00000".equals(resultCode)){
            return  agreementrestmp;
        }else{
            throw new  BaseBusinessException( resultCode,agreementrestmp.getResultDesc());
        }

    }
    //   该接口用于用户进行签署时先要发送短信验证码。
    // 如userId是个人或子用户则发送至注册手机号上。
    // 如userId是企业用户id,则发送至企业联系人手机号上。
    // 如用户未收到短信验证码,可重新调用此接口进行重新发送验证码。
    public static String doSignWithSendCode(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {

        String url = fxyurl+"opensignapi/sign/agreement/doSignWithSendCode.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);
        paramMap.put("userId",fxyUser.getUserId());
        paramMap.put("caseNumber",fxyUser.getCaseNumber());
        paramMap.put("writNumber",fxyUser.getWritNumber());
        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);

        JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
        String  resultCode =   myJsonroot.get("resultCode").toString();

        if("E00000".equals(resultCode)){
            return  myJsonroot.get("resultData").toString();
        }else{
            throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
        }

    }
    //   11.3.	用户签署验证码核验接口。
    public static String doSignWithVerifyCode(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {

        String url = fxyurl+"opensignapi/sign/agreement/doSignWithVerifyCode.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);
        paramMap.put("userId",fxyUser.getUserId());
        paramMap.put("caseNumber",fxyUser.getCaseNumber());
        paramMap.put("writNumber",fxyUser.getWritNumber());
        paramMap.put("mobCode",fxyUser.getMobCode());
        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);

        JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
        String  resultCode =   myJsonroot.get("resultCode").toString();

        if("E00000".equals(resultCode)){
            return  myJsonroot.get("resultData").toString();
        }else{
            throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
        }

    }
    //   用户签署页面跳转接口
    public static String goToUserSign(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {

        String url = fxyurl+"opensignapi/sign/agreement/goToUserSign.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);
        paramMap.put("userId",fxyUser.getUserId());
        paramMap.put("caseNumber",fxyUser.getCaseNumber());
        paramMap.put("writNumber",fxyUser.getWritNumber());
        paramMap.put("signMethods",fxyUser.getSignMethods());
        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result=pjmap(paramMap,url+"?");
        System.out.println("result="+result);
        return result;


    }
    //   该接口用于用户按批次编号进行签署。根据实际业务配置，调用前序接口（如用户签署发送验证码接口、用户签署身份认证接口）后，调用此接口。
    // 所进行的前序接口需要caseNumber,writNumber,userId参数值需一致。
    // 用户必须先实名完成才可调用此接口.签署的前序接口的有效时间10分钟，如过期需从头开始。
    public static String doSign(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {

        String url = fxyurl+"opensignapi/sign/agreement/doSign.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);
        paramMap.put("userId",fxyUser.getUserId());
        paramMap.put("caseNumber",fxyUser.getCaseNumber());
        paramMap.put("writNumber",fxyUser.getWritNumber());
        paramMap.put("signMethods",fxyUser.getSignMethods());
        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result=pjmap(paramMap,url+"?");
        System.out.println("result="+result);
        return result;


    }

    //   批次状态查询接口
    public static String searchWrit(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {

        String url = fxyurl+"opensignapi/sign/agreement/searchWrit.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);
        paramMap.put("writNumber",fxyUser.getWritNumber());
        paramMap.put("agreementCode",fxyUser.getAgreementCode());
        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);

        JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
        String  resultCode =   myJsonroot.get("resultCode").toString();
        if("E00000".equals(resultCode)){
            return  myJsonroot.get("resultData").toString();
        }else{
            throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
        }

    }


    //   用户授权签署接口
    public static String doAuthSign(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {

        String url = fxyurl+"opensignapi/sign/agreement/doAuthSign.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);
        paramMap.put("userId",fxyUser.getUserId());
        paramMap.put("caseNumber",fxyUser.getCaseNumber());
        paramMap.put("writNumber",fxyUser.getWritNumber());
        paramMap.put("signMethods",fxyUser.getSignMethods());
        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);

        JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
        String  resultCode =   myJsonroot.get("resultCode").toString();

        if("E00000".equals(resultCode)){
            return  myJsonroot.get("resultData").toString();
        }else{
            throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
        }

    }
    //   文书状态查询接口
    public static String viewAgreement(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {

        String url = fxyurl+"opensignapi/sign/agreement/viewAgreement.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);
        paramMap.put("agreementCode",fxyUser.getAgreementCode());
        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);

        JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
        String  resultCode =   myJsonroot.get("resultCode").toString();


        if("E00000".equals(resultCode)){
            return  myJsonroot.get("resultData").toString();
        }else{
            throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
        }

    }


//    文书下载接口
public static String downLoad(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {
    String url = fxyurl+"opensignapi/sign/agreement/downLoad.json";
    LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);
    paramMap.put("caseNumber",fxyUser.getCaseNumber());
    paramMap.put("writNumber",fxyUser.getWritNumber());
    paramMap.put("agreementCodes",fxyUser.getAgreementCode());
    String sign = createSign(paramMap,fxyappkey);
    paramMap.put("sign",sign);
    String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
    System.out.println("result="+result);

    JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
    String  resultCode =   myJsonroot.get("resultCode").toString();


    if("E00000".equals(resultCode)){
        return  myJsonroot.get("resultData").toString();
    }else{
        throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
    }

}




    //    文书拒绝签署接口
    public static String refuseBatchByCase(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {

        String url = fxyurl+"opensignapi/sign/agreement/refuseBatchByCase.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);
        paramMap.put("caseNumber",fxyUser.getCaseNumber());
        paramMap.put("writNumbers",fxyUser.getWritNumber());
        paramMap.put("userId",fxyUser.getUserId());
        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);

        JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
        String  resultCode =   myJsonroot.get("resultCode").toString();


        if("E00000".equals(resultCode)){
            return  myJsonroot.get("resultData").toString();
        }else{
            throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
        }

    }


    //    个人用户拒绝签署页面接口
    public static String goToRefuseSign(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {

        String url = fxyurl+"opensignapi/sign/agreement/goToRefuseSign.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);
        paramMap.put("caseNumber",fxyUser.getCaseNumber());
        paramMap.put("writNumber",fxyUser.getWritNumber());
        paramMap.put("userId",fxyUser.getUserId());
        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);
        JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
        String  resultCode =   myJsonroot.get("resultCode").toString();
        if("E00000".equals(resultCode)){
            return  myJsonroot.get("resultData").toString();
        }else{
            throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
        }
    }
    //    批次提取接口
    public static String extractWrit(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {

        String url = fxyurl+"opensignapi/sign/agreement/extractWrit.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);
        paramMap.put("extractCode",fxyUser.getExtractCode());
        paramMap.put("userId",fxyUser.getUserId());
        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);

        JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
        String  resultCode =   myJsonroot.get("resultCode").toString();


        if("E00000".equals(resultCode)){
            return  myJsonroot.get("resultData").toString();
        }else{
            throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
        }

    }
//    重新发送提取码接口
public static String reSendInvitation(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {
    String url = fxyurl+"opensignapi/sign/agreement/reSendInvitation.json";
    LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);
    paramMap.put("userId",fxyUser.getUserId());
    paramMap.put("caseNumber",fxyUser.getCaseNumber());
    paramMap.put("writNumber",fxyUser.getWritNumber());
    String sign = createSign(paramMap,fxyappkey);
    paramMap.put("sign",sign);
    String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
    System.out.println("result="+result);

    JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
    String  resultCode =   myJsonroot.get("resultCode").toString();


    if("E00000".equals(resultCode)){
        return  myJsonroot.get("resultData").toString();
    }else{
        throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
    }

}
//    批次列表接口 rest
public static String writList(String appCode,RedisUtil redisUtil,fxyUser fxyUser)throws BaseBusinessException {
    String url = fxyurl+"opensignapi/sign/agreement/writList.json";
    LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);
    paramMap.put("userId",fxyUser.getUserId());
    paramMap.put("pageNo","1");
    paramMap.put("pageSize","20");
    String sign = createSign(paramMap,fxyappkey);
    paramMap.put("sign",sign);
    String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
    System.out.println("result="+result);

    JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
    String  resultCode =   myJsonroot.get("resultCode").toString();


    if("E00000".equals(resultCode)){
        return  myJsonroot.get("resultData").toString();
    }else{
        throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
    }

}
//申办订单相关材料下载接口 rest
public static String bidorderDownLoad(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {
    String url = fxyurl+"opensignapi/sign/bidorder/downLoad.json";
    LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode, redisUtil);
    paramMap.put("orderNumber",fxyUser.getOrderNumber());
    String sign = createSign(paramMap,fxyappkey);
    paramMap.put("sign",sign);
    String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
    System.out.println("result="+result);

    JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
    String  resultCode =   myJsonroot.get("resultCode").toString();


    if("E00000".equals(resultCode)){
        return  myJsonroot.get("resultData").toString();
    }else{
        throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
    }

}
//申请出证接口 rest
    public static String applyCert(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {

        String url = fxyurl+"opensignapi/sign/bidorder/applyCert.json";
        LinkedHashMap<String, Object> paramMap  = getcompara(fxyappid,appCode, redisUtil);
        paramMap.put("userId",fxyUser.getUserId());
        paramMap.put("serialNumber",fxyUser.getOrderNumber());
        paramMap.put("applicantUserId",fxyUser.getApplicantUserId());
        paramMap.put("businessType",fxyUser.getBusinessType());
        paramMap.put("materialType",fxyUser.getMaterialType());
        paramMap.put("materialData",fxyUser.getMaterialData());
        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);

        JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
        String  resultCode =   myJsonroot.get("resultCode").toString();


        if("E00000".equals(resultCode)){
            return  myJsonroot.get("resultData").toString();
        }else{
            throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
        }

    }
    //补充材料 rest
    public static String supplyMaterials(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {

        String url = fxyurl+"opensignapi/sign/bidorder/supplyMaterials.json";
        LinkedHashMap<String, Object> paramMap  = getcompara(fxyappid,appCode,redisUtil);
        paramMap.put("orderNumber",fxyUser.getOrderNumber());
        paramMap.put("userId",fxyUser.getUserId());
        paramMap.put("fileId",fxyUser.getFileIds());
        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);

        net.sf.json.JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
        String  resultCode =   myJsonroot.get("resultCode").toString();


        if("E00000".equals(resultCode)){
            return  myJsonroot.get("resultData").toString();
        }else{
            throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
        }

    }
    //订单受理进度查询 rest
    public static String searchBidOrderStatus(String appCode,RedisUtil redisUtil,fxyUser fxyUser) throws BaseBusinessException {

        String url = fxyurl+"opensignapi/sign/bidorder/searchBidOrderStatus.json";
        LinkedHashMap<String, Object> paramMap = getcompara(fxyappid,appCode,redisUtil);
        paramMap.put("orderNumber",fxyUser.getOrderNumber());
        paramMap.put("serialNumber",fxyUser.getSerialNumber());
        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);

        JSONObject myJsonroot = (JSONObject)  JSONObject.fromObject(result);
        String  resultCode =   myJsonroot.get("resultCode").toString();


        if("E00000".equals(resultCode)){
            return  myJsonroot.get("resultData").toString();
        }else{
            throw new  BaseBusinessException( resultCode,myJsonroot.get("resultDesc").toString());
        }

    }
    /***
     * Get MD5 of one file！test ok!
     *
      * @return
     */
    public static String getFileMD5(String fileName) {
        try{
            return DigestUtils.md5Hex(new FileInputStream(new File(fileName))) ;

        }catch (Exception e){
  return  "";
        }
    }
    public static   long getfilelenth(String fileUrl){
    File f = null;
    String path;
    long len = 0;
    boolean bool = false;
    try{
        f = new File(fileUrl);
        bool = f.exists();
        if(bool)
        {
            len = f.length();
        }
    }catch(Exception e){
        // if any error occurs

    }
    return len;

}

    public static String createSignString(LinkedHashMap<String, String> params,String key) {
        Set<String> keysSet = params.keySet();
        Object[] keys = keysSet.toArray();
        Arrays.sort(keys);
        StringBuffer temp = new StringBuffer();
        int last = 0;
        int mapsize = params.size();
        for (Object t:keys) {
            last = last + 1;
            temp.append(t.toString() +"=");
            Object value = params.get(t.toString());;
            String valueString = "";
            if (null != value) {
                valueString = String.valueOf(value);
                temp.append(valueString.toString());
            }
            if(last!=mapsize ){
                temp.append("&");
            }

        }
        temp.append(key);

        return DigestUtils.md5Hex(temp.toString().getBytes(Charset.forName("UTF-8")));
    }
    public static String pjmap(LinkedHashMap<String, Object> params,String url) {
        Set<String> keysSet = params.keySet();
        Object[] keys = keysSet.toArray();
        Arrays.sort(keys);
        StringBuffer temp = new StringBuffer();
        temp.append(url);
        int last = 0;
        int mapsize = params.size();
        for (Object t:keys) {
            last = last + 1;
            temp.append(t.toString() +"=");
            Object value = params.get(t.toString());;
            String valueString = "";
            if (null != value) {
                valueString = String.valueOf(value);
                temp.append(valueString.toString());
            }
            if(last!=mapsize ){
                temp.append("&");
            }

        }
        return temp.toString();
    }
    public static String createSign(LinkedHashMap<String, Object> params,String key) {
        Set<String> keysSet = params.keySet();
        Object[] keys = keysSet.toArray();
        Arrays.sort(keys);
        StringBuffer temp = new StringBuffer();
        int last = 0;
        int mapsize = params.size();
       for (Object t:keys) {
            last = last + 1;
            temp.append(t.toString() +"=");
            Object value = params.get(t.toString());;
            String valueString = "";
            if (null != value) {
                valueString = String.valueOf(value);
                temp.append(valueString.toString());
            }
            if(last!=mapsize ){
                temp.append("&");
            }

        }
        temp.append(key);

       System.out.println("temp="+temp.toString());

        return DigestUtils.md5Hex(temp.toString().getBytes(Charset.forName("UTF-8")));
    }


    private   static JSONObject  getAgreementInfo(String agreementCode,String templateCode,String agreementName, List<conmap> conmapLis,String userIds,String signatorys) {
         JSONObject agreementInfo = new JSONObject();
        if(StringUtil.isEmpty(agreementCode)){
            agreementCode = DateUtils.date2Str(DateUtils.yyyymmddhhmmss);
        }
        agreementInfo.put("agreementCode",agreementCode);
        agreementInfo.put("templateCode", templateCode);
        agreementInfo.put("agreementName", agreementName);
        agreementInfo.put("varValues", getVarValues(conmapLis));
        agreementInfo.put("signUsers", getSignUsers(userIds,signatorys));
        return agreementInfo;
      }
    private  static JSONArray  getAgreementInfosfromlist(List<fxyUser> listfxyuser) {
        JSONArray agreementInfos = new JSONArray();
        for(fxyUser t:listfxyuser){
            JSONObject agreementInfo = new JSONObject();
            agreementInfo =  getAgreementInfo(t.getAgreementCode(),t.getTemplateCode(),
                    t.getAgreementName(),t.getConmapList(),t.getUserIds(),t.getSignatorys());
            agreementInfos.add(agreementInfo);
        }

        return agreementInfos;
    }

    private  static JSONArray  getAgreementInfos(String agreementCode,String templateCode,String agreementName, List<conmap> conmapLis,String userIds,String signatorys) {
        JSONArray agreementInfos = new JSONArray();
        JSONObject agreementInfo = new JSONObject();
        if(StringUtil.isEmpty(agreementCode)){
            agreementCode = DateUtils.date2Str(DateUtils.yyyymmddhhmmss);
        }
        agreementInfo.put("agreementCode",agreementCode);
        agreementInfo.put("templateCode", templateCode);
        agreementInfo.put("agreementName", agreementName);
        agreementInfo.put("varValues", getVarValues(conmapLis));
        agreementInfo.put("signUsers", getSignUsers(userIds,signatorys));
        agreementInfos.add(agreementInfo);
        return agreementInfos;
    }

    private static JSONArray getSignUsers(String userIds, String signatorys) {
        JSONArray signUsers = new JSONArray();
        String[] useridarray = userIds.split(",");
        String[] signatoryarray = signatorys.split(",");
        int i = 0;
        for(String user:useridarray){
            JSONObject signUser = new JSONObject();
            signUser.put("userId", user);
            signUser.put("signatory", signatoryarray[i]);
            i++;
            signUsers.add(signUser);
        }
        return signUsers;
    }

    private  static JSONObject getVarValues(List<conmap> conmapList) {
        JSONObject varValue = new JSONObject();
        for (conmap map : conmapList){
            try{
                if(StringUtil.isNotEmpty(map.getConValue())){
                    varValue.put(map.getConKey(), map.getConValue());
                }
            }catch (Exception e){
            }
        }
        return varValue;
    }


    private static LinkedHashMap<String, Object>  getcompara(String appId,String appCode,RedisUtil redisUtil){
        LinkedHashMap<String, Object> paramMap = new LinkedHashMap<String, Object>();
        paramMap.put("appId",appId);
        paramMap.put("charset","utf-8");
        paramMap.put("format","json");
        paramMap.put("signTime",DateUtils.getDataString(DateUtils.yyyymmddhhmmss));
        paramMap.put("signType","MD5");
        paramMap.put("token",gettoken(appCode,redisUtil));
        paramMap.put("version","2.1");
        return paramMap;
    }

    private  static LinkedHashMap<String, String>  getcomparaString(String appId, String appCode,RedisUtil redisUtil){
        LinkedHashMap<String, String> paramMap = new LinkedHashMap<String, String>();
        paramMap.put("appId",appId);
        paramMap.put("charset","utf-8");
        paramMap.put("format","json");
        paramMap.put("signTime",DateUtils.getDataString(DateUtils.yyyymmddhhmmss));
        paramMap.put("signType","MD5");
        paramMap.put("token",gettoken(appCode,redisUtil));
        paramMap.put("version","2.1");
        return paramMap;
    }

    public static   String gettoken(String appCode,RedisUtil redisUtil){
        if(redisUtil.hasKey(appCode)){
            return (String) redisUtil.get(appCode);
        }

        String url = fxyurl+"opensignapi/sign/auth/getToken.json";
        LinkedHashMap<String, Object> paramMap = new LinkedHashMap<String, Object>();
        paramMap.put("appId",fxyappid);
        paramMap.put("charset","utf-8");
        paramMap.put("signTime",DateUtils.getDataString(DateUtils.yyyymmddhhmmss));
        paramMap.put("format","json");
        paramMap.put("signType","MD5");
        paramMap.put("version","2.1");
        String sign = createSign(paramMap,fxyappkey);
        paramMap.put("sign",sign);
        String result= com.xiaoleilu.hutool.http.HttpUtil.post(url,paramMap);
        System.out.println("result="+result);
        fxytokenRes fxyRes = JSONHelper.fromJsonToObject(result, fxytokenRes.class);
        if("E00000".equals(fxyRes.getResultCode())){
            redisUtil.set(appCode,fxyRes.getResultData().getToken(),fxyRes.getResultData().getExpires());
             return fxyRes.getResultData().getToken();
        }else{
            return "";
        }

    }
    public static String postFileMultiPart(String url,Map<String,ContentBody> reqParam)throws ClientProtocolException, IOException{

        CloseableHttpClient httpclient = HttpClients.createDefault();
        try {
            // 创建httpget.
            HttpPost httppost = new HttpPost(url);

            //setConnectTimeout：设置连接超时时间，单位毫秒。setConnectionRequestTimeout：设置从connect Manager获取Connection 超时时间，单位毫秒。这个属性是新加的属性，因为目前版本是可以共享连接池的。setSocketTimeout：请求获取数据的超时时间，单位毫秒。 如果访问一个接口，多少时间内无法返回数据，就直接放弃此次调用。
            RequestConfig defaultRequestConfig = RequestConfig.custom().setConnectTimeout(5000).setConnectionRequestTimeout(5000).setSocketTimeout(15000).build();
            httppost.setConfig(defaultRequestConfig);

            System.out.println("executing request " + httppost.getURI());

            MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
            for(Map.Entry<String,ContentBody> param : reqParam.entrySet()){
                multipartEntityBuilder.addPart(param.getKey(), param.getValue());
            }
            HttpEntity reqEntity = multipartEntityBuilder.build();
            httppost.setEntity(reqEntity);

            // 执行post请求.
            CloseableHttpResponse response = httpclient.execute(httppost);

            System.out.println("got response");

            try {
                // 获取响应实体
                HttpEntity entity = response.getEntity();
                //System.out.println("--------------------------------------");
                // 打印响应状态
                //System.out.println(response.getStatusLine());
                if (entity != null) {
                    return EntityUtils.toString(entity,Charset.forName("UTF-8"));
                }
                //System.out.println("------------------------------------");
            } finally {
                response.close();

            }
        } finally {
            // 关闭连接,释放资源
            try {
                httpclient.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return null;

    }
}
